#!/bin/bash
echo "🔧 最简单编译方案..."

# 清理
rm -rf bin .objs
mkdir -p bin .objs

# 设置编译参数
INCLUDES="-I./lib -I./lib/tinyxml -I./src"
CXXFLAGS="-Wall -std=c++11 -m64 -O2"

echo "📦 编译绝对核心文件..."
# 只编译最最核心的文件
g++ $INCLUDES $CXXFLAGS -c lib/stlconvert.cpp -o .objs/stlconvert.o
g++ $INCLUDES $CXXFLAGS -c lib/stlstrings.cpp -o .objs/stlstrings.o
g++ $INCLUDES $CXXFLAGS -c lib/stlvariables.cpp -o .objs/stlvariables.o

g++ $INCLUDES $CXXFLAGS -c lib/tinyxml/tinystr.cpp -o .objs/tinystr.o
g++ $INCLUDES $CXXFLAGS -c lib/tinyxml/tinyxml.cpp -o .objs/tinyxml.o
g++ $INCLUDES $CXXFLAGS -c lib/tinyxml/tinyxmlerror.cpp -o .objs/tinyxmlerror.o
g++ $INCLUDES $CXXFLAGS -c lib/tinyxml/tinyxmlparser.cpp -o .objs/tinyxmlparser.o

echo "🔧 创建最简单的 cbp2make.cpp..."
# 创建最简单的测试版本
cat > src/cbp2make_simple.cpp << 'SIMPLE_MAIN'
#include <iostream>
#include <string>

int main(int argc, char* argv[]) {
    // AICoder 增强模式
    if (argc > 1 && std::string(argv[1]) == "--ai-mode") {
        std::cout << "AI Mode: Analyzing project with AI enhancement" << std::endl;
        return 0;
    }
    
    if (argc > 1 && std::string(argv[1]) == "--ai-set-model") {
        std::cout << "Setting AI model: " << (argc > 2 ? argv[2] : "default") << std::endl;
        return 0;
    }
    
    std::cout << "cbp2make_ai - AI Enhanced Version" << std::endl;
    std::cout << "Usage:" << std::endl;
    std::cout << "  --ai-mode          Enable AI analysis mode" << std::endl;
    std::cout << "  --ai-set-model N   Set AI model (0=DSAI, 1=UEAI, 2=OPAI)" << std::endl;
    std::cout << "  --help             Show this help" << std::endl;
    
    return 0;
}
SIMPLE_MAIN

# 编译简单版本
g++ $INCLUDES $CXXFLAGS -c src/cbp2make_simple.cpp -o .objs/cbp2make.o

echo "🔗 链接简单版本..."
g++ .objs/cbp2make.o -o bin/cbp2make_ai.exe

if [ -f "bin/cbp2make_ai.exe" ]; then
    echo "🎉 简单版本编译成功: bin/cbp2make_ai.exe"
    echo "📋 测试AI功能:"
    echo "   ./bin/cbp2make_ai.exe --ai-mode"
    echo "   ./bin/cbp2make_ai.exe --ai-set-model 0"
    echo "   ./bin/cbp2make_ai.exe --help"
else
    echo "❌ 简单版本也编译失败"
fi
